home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Browsers, Managers & Extensions / IE Tab 1.5.2 / ie_tab-1.5.20080618-fx-win.xpi / chrome / content / ietabExtApp.js < prev    next >
Text File  |  2008-03-01  |  2KB  |  55 lines

  1. var IeTabExtApp = {
  2.  
  3.    HKEY_CLASSES_ROOT: 0,
  4.    HKEY_CURRENT_CONFIG: 1,
  5.    HKEY_CURRENT_USER: 2,
  6.    HKEY_LOCAL_MACHINE: 3,
  7.    HKEY_USERS: 4,
  8.  
  9.    getRegistryEntry: function(regRoot, regPath, regName) {
  10.       try {
  11.          if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
  12.             var nsIWindowsRegKey = Components.classes["@mozilla.org/windows-registry-key;1"].getService(Components.interfaces.nsIWindowsRegKey);
  13.             var regRootKey = new Array(0x80000000, 0x80000005, 0x80000001, 0x80000002, 0x80000003);
  14.             nsIWindowsRegKey.open(regRootKey[regRoot], regPath, Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
  15.             if (nsIWindowsRegKey.valueCount)
  16.                return nsIWindowsRegKey.readStringValue(regName);
  17.          }
  18.       } catch(e) {}
  19.       return null;
  20.    },
  21.  
  22.    getIExploreExePath: function() {
  23.       var regRoot = this.HKEY_LOCAL_MACHINE;
  24.       var regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE";
  25.       var regName = "";
  26.       return this.getRegistryEntry(regRoot, regPath, regName);
  27.    },
  28.  
  29.    removeArrayNullElements: function(a) {
  30.       var result = [];
  31.       while(a.length) {
  32.          var elmt = a.shift();
  33.          if (elmt) result.push(elmt);
  34.       }
  35.       return result;
  36.    },
  37.  
  38.    runApp: function(filename, parameter) {
  39.       try {
  40.          if ((!filename) || (filename == "")) filename = this.getIExploreExePath();
  41.          var nsILocalFile = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
  42.          nsILocalFile.initWithPath(filename);
  43.          if (nsILocalFile.exists()) {
  44.             var paramArray = parameter ? parameter.split(/\s*\"([^\"]*)\"\s*|\s+/) : [];
  45.             paramArray = this.removeArrayNullElements(paramArray);
  46.             var nsIProcess = Components.classes["@mozilla.org/process/util;1"].getService(Components.interfaces.nsIProcess);
  47.             nsIProcess.init(nsILocalFile);
  48.             nsIProcess.run(false, paramArray, paramArray.length);
  49.             return true;
  50.          }
  51.       } catch(e) {}
  52.       return false;
  53.    }
  54. };
  55.